package com.itheima.pinda.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pinda.DTO.transportline.TransportLineTypeDto;
import com.itheima.pinda.common.utils.PageResponse;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdTransportLineTypeService;
import com.itheima.pinda.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "线路类型")
@RestController
@RequestMapping(value = "/base/type")
public class PdTransportLineTypeController {

    @Autowired
    private PdTransportLineTypeService transportLineTypeService;

    @ApiOperation(value = "新增线路类型")
    @PostMapping(value = "/insert")
    public TransportLineTypeDto insert(TransportLineTypeDto transportLineTypeDto){
        return transportLineTypeService.insert(transportLineTypeDto);
    }

    @ApiOperation(value = "更新线路类型")
    @PostMapping(value = "/update")
    public TransportLineTypeDto update(TransportLineTypeDto transportLineTypeDto) {
        return transportLineTypeService.insert(transportLineTypeDto);
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/id")
    public TransportLineTypeDto selectById(@RequestParam("id") String id){

        return transportLineTypeService.selectById(id);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/selectByPage")
    public PageResponse selectByPage(@RequestParam("pageNum")Integer pageNum,
                                     @RequestParam("pageSize")Integer pageSize,
                                     @RequestParam(value = "typeNumber",required = false)String typeNumber,
                                     @RequestParam(value = "name",required = false)String name,
                                     @RequestParam(value = "agencyType",required = false)Integer agencyType){
        IPage page = transportLineTypeService.selectByPage(pageNum, pageSize, typeNumber, name, agencyType);

        return ResultUtils.pageResult(pageNum,pageSize,page);
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping(value = "/ids")
    public Result deleteById(@RequestParam("ids") List<String> ids){

        transportLineTypeService.deleteById(ids);
        return Result.ok("删除成功！");
    }
}
